package com.starblink.login.deletionconfirm.ui

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.starblink.android.basic.base.activity.BaseTVMActivity
import com.starblink.android.basic.ext.click
import com.starblink.android.basic.widget.ConfirmDialog
import com.starblink.android.basic.user.login.LoginManager
import com.starblink.basic.route.RoutePage
import com.starblink.basic.style.title.OnTitleBarListener
import com.starblink.basic.style.title.TitleBar
import com.starblink.basic.util.ActivityStackManage
import com.starblink.basic.util.CommUtils
import com.starblink.login.databinding.ActivityDeletionConfirmBinding

//DeleteAccountConfirmRoute.dart
@Route(path = RoutePage.Login.DELETION_CONFIRM)
class DeletionConfirmActivity :
    BaseTVMActivity<ActivityDeletionConfirmBinding, DeletionConfirmVM>() {

    override fun initViewBinding(): ActivityDeletionConfirmBinding =
        ActivityDeletionConfirmBinding.inflate(layoutInflater)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        viewBinding.titleBar.setOnTitleBarListener(object : OnTitleBarListener {
            override fun onLeftClick(titleBar: TitleBar?) {
                finish()
            }
        })

        viewBinding.adcConfirmBtn.click {
            viewModel.deleteAccount {
                ConfirmDialog.Builder(this)
                    .setTitle(CommUtils.getString(com.starblink.basic.style.R.string.delete_account_dialog_t1))
                    .setMessage(CommUtils.getString(com.starblink.basic.style.R.string.delete_account_dialog_t2))
                    .setSureButton(
                        textId = com.starblink.basic.style.R.string.confirm
                    ) { dialop, p1 ->
                        run {
                            dialop.dismiss()
                            // 登出，返回首页
                            LoginManager.logout()
                            ActivityStackManage.toMainActivity()
                        }
                    }
                    .hideCanCancelBtn()
                    .setCanCancel(false)
                    .create().show()
            }
        }

        viewBinding.adcCancel.click {
            finish()
        }
    }

}